//
//  MovieTableViewcell.m
//  LZMPro
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 LZS. All rights reserved.
//

#import "MovieTableViewcell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"
@implementation MovieTableViewcell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
//    self = [super init];
    if (self) {
        [self createSubviews];
    }
    return self;
}

//-(instancetype)initWithFrame:(CGRect)frame{
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self createSubviews];
//        
//    }
//    return self;
//}

-(void)createSubviews{
    
    self.myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 200)];
    [self.contentView addSubview:self.myImageView];
//    self.myImageView.backgroundColor = IMAGVIEWDEFAULTCOLOR;
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 90, 375, 20)];
    self.titleLabel.font = [UIFont systemFontOfSize:18 weight:16];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleLabel];

    
    self.typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(82, 120, 100, 20)];
    self.typeLabel.font = [UIFont systemFontOfSize:14];
    self.typeLabel.textAlignment = NSTextAlignmentRight;
    self.typeLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.typeLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(187, 120, 100, 20)];
    self.timeLabel.font = [UIFont systemFontOfSize:14];
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    self.timeLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.timeLabel];

}

//自定义一个方法
-(void)setCellVithModel:(MovieModel *)model{
    
//    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:model.coverForFeed] placeholderImage:[UIImage imageNamed:nil]];
    
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:model.coverForFeed]];
    
    self.titleLabel.text = model.title;
    self.typeLabel.text = [NSString stringWithFormat:@"#%@",model.category];
    
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    NSInteger timeTotal = [numberFormatter stringFromNumber:model.duration].integerValue;
    
    if (timeTotal >= 60) {
        NSInteger minute = timeTotal / 60;
        NSInteger seconds = timeTotal % 60;
        NSString *timeStr = [NSString stringWithFormat:@" / %ld'%ld\"",minute,seconds];
        self.timeLabel.text = timeStr;
        //        NSString *secondsStr = [NSString stringWithFormat:@"%ld\"",seconds];
    }else{
        NSString *timeStr = [NSString stringWithFormat:@" / %ld\"",timeTotal];
        self.timeLabel.text = timeStr;
    }
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
